import {defineStore} from 'pinia'
import {reactive} from 'vue'
import {
	request_get_business_detail
} from '../service/business'

// 定义商家详情数据类型
interface StoreVO {
	storeLogo: string
	storeName: string
}

interface BusinessData {
	storeVOList?: StoreVO[]
	businessLicense?: string
	businessName?: string
	// 可以根据实际API响应添加更多字段
	[key: string]: any
}

interface BusinessResponse {
	data: BusinessData
	code?: string
	success?: boolean
	message?: string
}

export default defineStore('useBusinessStore', () => {
	
	const businessDetail = reactive({
		business: {} as BusinessData
	})
	
	// 前台管理:商家基本信息详情
	const findBusinessId = async (id: number) => {
		let res = await request_get_business_detail(id) as BusinessResponse
		console.log(res?.data, "| 商家基本信息");
		res.data.storeVOList = res.data.storeVOList && Array.isArray(res.data.storeVOList) ? res.data.storeVOList : new Array(3).fill('').map((_, idx) => {
			return {
				storeLogo: res?.data?.businessLicense,
				storeName: res?.data?.businessName + '-' + idx
			}
		})
		businessDetail.business = res?.data
	}
	return { 
		findBusinessId,
		businessDetail
	}
})